<?php
include_once 'inc/config.inc.php';
include_once 'inc/mysql.inc.php';
include_once 'inc/tool.ins.php';

$template['title'] = '密码修改';
$link = connect();
?>


<?php  include 'include/header.php' ?>
<div id="content" class="span10">


        <ul class="breadcrumb">
            <li>
                <i class="icon-home"></i>
                <a href="index.php">Home</a>
                <i class="icon-angle-right"></i>
            </li>
            <li><a href="#">修改密码</a></li>

        </ul>

    <?php
     $num=$_COOKIE['hbw']['sid'];
     $query = "select * from user where sid='$num' ";
     $result = execute($link,$query);
     $data = mysqli_fetch_array($result);
    ?>

    <h2>个人信息：</h2>
    学号：<?php echo $data['sid']?><br>
    姓名：<?php echo $data['username']?><br>
    密码：<?php echo '******'?><br>
    性别：<?php echo $data['sex']?><br><br>

    <h2>密码修改：</h2>
    <form  method="post">
        原密码：<input type="text" name="oldPw"  ><br>
        新密码：<input type="text" name="newPw"  ><br>
        再次输入新密码：<input type="text" name="newPw2"  ><br>
         <input type="submit" name="submit" value="点击修改">
    </form>


    <?php
          if(isset($_POST['submit'])){
               if($data['password'] == $_POST['oldPw']){ //假如输入的密码跟原密码一样
                    if($_POST['newPw'] == $_POST['newPw2']){ //假如输入的俩次密码相同
                         $query = "update user set password= {$_POST['newPw']} where sid= {$data['sid']}";
                          $result=execute($link,$query);
                           if(mysqli_affected_rows($link)){
                              skip('index.php','glyphicon-ok-sign','修改成功');
                           }else{
                           skip('chanage.php','glyphicon-remove-sign','修改失败');
                        }

                    }else{
                       skip('chanage.php','glyphicon-remove-sign','俩次密码不同');
                    }
               }
               skip('chanage.php','glyphicon-remove-sign','原始密码输入错误');

          }

    ?>


</div>
<?php  include 'include/footer.php' ?>